<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="/static/js/jquery-3.5.1.min.js"></script>

    <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css"/>
    <script type="text/javascript"src="/static/layui/layui.js"></script>
    <meta charset="utf-8">
    <title></title>
</head>
<script type="text/javascript">
    function toreg() {
        location.href="/user/toReg"
    }

    function getEmailCode() {
        var userName= $("#userName").val();
        if(userName!=""){
            $.ajax({
                url:"/user/getCode",
                type:"post",
                data:"userName="+userName,
                success:function (msg) {
                    if(msg=="1"){
                        alert("验证码已发送")
                    }else{
                        alert("用户名不存在")
                    }
                }
            });
        }else{
            alert("请输入用户名")
        }
    }
    function toLogin2() {
            $.ajax({
                url:"/user/login2",
                type:"post",
                data:$("#loginForm").serialize(),
                success:function (msg) {
                    if(msg=="1"){
                        location.href="/user/toIndex"
                    }else{
                        alert("验证码错误")
                    }
                }
            });

    }
</script>
<body>



<form class="layui-form" id="loginForm">
    <div style="margin-top: 12%;margin-left: 30%;">
        <label class="layui-form-label">账号：</label>
        <div class="layui-input-inline">
            <input type="text" name="userName" id="userName" required lay-verify="required" placeholder="请输入账户" autocomplete="off" class="layui-input">
        </div>
        <br />
        <label class="layui-form-label">验证码：</label>
        <div class="layui-input-inline">
            <input type="text" id="emailTxt" name="emailCode" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            <input type="button" onclick="getEmailCode()" value="获取验证码">
        </div>


        <div class="layui-form-item">

            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo" onclick="toLogin2()">登录</button>
                <button onclick="toreg()" type="reset" class="layui-btn layui-btn-primary">注册</button>
            </div>
        </div>
    </div>
</form>


</body>
</html>
